<?php

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class feedbackModel extends Model
{
    use SoftDeletes;

    protected $table = 'feedback';
    protected $primaryKey = 'id';
    protected $appends = ['status_name', 'type_name'];
    protected $hidden = [];

    protected static $AllType = [
        'feedback' => '咨询',
        'product' => '产品',
        'complaint' => '投诉',
        'propose' => '建议',
    ];
    /**
     * @param DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public static function getAllType()
    {
        return self::$AllType;
    }

    public function getTypeNameAttribute($value)
    {
        $type_name = '';
        if(in_array($this->attributes['type'], array_keys(self::$AllType))){
            $type_name = self::$AllType[$this->attributes['type']];
        }
        return $type_name;
    }

    public function getStatusNameAttribute($value)
    {
        $status_name = '待处理';

        if ($this->attributes['status'] > 0) {
            $status_name = '已处理';
        }

        return $status_name;
    }

    public function member()
    {
        return $this->belongsTo(\memberModel::class, 'user_id', 'id')->select(['id', 'phone', 'nickname', 'realname', 'avatar']);
    }

    public function oper()
    {
        return $this->belongsTo(adminModel::class, 'oper_id', 'id')->select(['id', 'username']);
    }

}